using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Elementum
{
    abstract public class Modifier
    {
        protected VisibleObject _registor;
        public int _counter;
        protected int _start;
        protected int _end;
        public delegate void ModifyDoneActionHandler();
        public event ModifyDoneActionHandler ModifyDoneAction;
        public delegate void OnModifyActionHandler();
        public event OnModifyActionHandler OnModifyAction;
        public bool _isModifyDone;

        public Modifier(int start,int end) {
            if (end <= start)
                throw new Exception("End most bigger than start!!");
            _registor = null;
            _counter = 0;
            _start = start;
            _end = end;
            _isModifyDone = false;
        }



        public void Register(VisibleObject registor) {
            _registor = registor;
        }

        public void UnRegister(){ 
            _registor = null;
            _counter = 0;
        }

        protected abstract void OnModify();

        protected virtual void ModifyDone() {
            if (ModifyDoneAction != null)
                ModifyDoneAction();
            _isModifyDone = true;
        }

        public void Update() {
            if (_counter <= _end)
            _counter++;
            if (_counter >= _start && _counter <= _end)
                if (_registor != null)
                {
                    if (OnModifyAction != null)
                        OnModifyAction();
                    OnModify();
                }
            if (_counter == _end && _registor != null)
            {
                ModifyDone();
            } 
            
        }

    }
}
